package org.ykh.gmall.common.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author ykh
 */
@Configuration
public class ThreadPoolConfig {


    @Bean
    public ThreadPoolExecutor executor(){


        return new ThreadPoolExecutor(
                50, //核心线程数
                200,//最大线程数据
                30,//闲置时间
                TimeUnit.SECONDS,//时间单位
                new ArrayBlockingQueue<>(10000)//阻塞队列
                , r -> new Thread(r,"商品详情-异步编排线程"+ new Random().nextInt())
        );

    }
}
